/*jshint esversion: 9 */
import {
    service,
} from "./Request";
import qs from 'qs';
import { userData as userDataStore } from "@/store/User";

/** 公用接口 */
const allApi = {
    reguser(params) {
        return service({
            url: "/auth/register/admin",
            method: 'post',
            headers: { 'Content-Type': 'application/json' },
            data: JSON.stringify({
                userData: {
                    employeeId: params.employeeId,
                    password: params.password,
                    realName: params.realName,
                    contact: params.contact
                },
                adminCode: params.adminCode || 'FACTORY_ADMIN_2025'
            }),
        })
    },
    login(params) {
        return service({
            url: "/auth/login",
            method: 'post',
            headers: { 'Content-Type': 'application/json' },
            data: JSON.stringify({
                employeeId: params.employeeId,
                password: params.password
            })
        }).then(response => {
            console.log('API原始响应:', response); // 输出API响应
            // 登录成功后，保存token到store中
            if (response && (response.token || response.accessToken)) {
                const userData = userDataStore();
                const token = response.token || response.accessToken;
                userData.setToken(token);
                userData.setUserInfo(response.user || {});
            }
            return response;
        });
    },
    getUserInfo() {
        return Promise.resolve({
            "msg": "操作成功",
            "code": 200,
            data: {
                "userName": "admin",
                "nickName": "管理员",
                "avatar": 'https://s11.ax1x.com/2023/12/15/pihx4js.jpg',
            },
        });
    },
    getMenuList() {
        let menuList = [
            {
                name: "main-index",
                title: '首页',
                content: '(有缓存，并且标签页固定)',
                isCache: true,
                fixed: true,
                iconName: "svg:all-fill.svg",
            },
            {
                name: "new-tag-page",
                title: '新标签页',
                isCache: true,
                hidden: true,
            },
            {
                name: "main-401",
                title: '401页面',
                isCache: true,
                hidden: true,
            },
            {
                name: "main-404",
                title: '404页面',
                isCache: true,
                hidden: true,
            },
            {
                name: "main-mine-info",
                title: '个人中心',
                isCache: true,
                hidden: true,
            },
            {
                name: "main-mine-info-update",
                title: '个人信息修改',
                isCache: true,
                hidden: true,
            },
            {
                name: "main-mine-info-password",
                title: '修改密码',
                isCache: true,
                hidden: true,
            },
            {
                title: '信息管理',
                iconName: "svg:cog-fill.svg",
                childs: [
                    {
                        name: "role-list",
                        title: '全部计时记录',
                        isCache: true,
                        content: '',
                        iconName: "svg:laptop-check.svg",
                        showTagIcon: true,
                    },
                    {
                        name: "user-list",
                        title: '员工管理',
                        isCache: true,
                        content: '',
                        iconName: "svg:laptop-check.svg",
                        showTagIcon: true,
                    },
                    {
                        name: 'icon-list',
                        title: '工作种类管理',
                        isCache: true,
                        content: '',
                        iconName: 'svg:laptop-check.svg',
                        showTagIcon: true,
                    },
                    {
                        name: 'verification-list',
                        title: '实名认证列表',
                        isCache: true,
                        content: '',
                        iconName: 'svg:laptop-check.svg',
                    },
                ],
            },
            {
                name: 'show-list',
                title: '查询员工计时记录',
                iconName: 'svg:laptop-check.svg',
            },
            {
                name: "merge-table",
                title: '添加工作种类',
                iconName: "svg:laptop-check.svg",
            },
            {
                name: "show-list-info",
                title: '数据详情',
                hidden: true,
                iconName: "svg:all-fill.svg",
            },
            {
                name: "show-list-add",
                title: '数据添加',
                hidden: true,
                iconName: "svg:Navbar-full.svg",
            },
            {
                name: "show-list-update",
                title: '数据编辑',
                hidden: true,
                isCache: true,
                content: '(有缓存)',
                iconName: "svg:Navbar-full.svg",
            },
        ];
        return Promise.resolve({
            "msg": "操作成功",
            "code": 200,
            data: menuList,
        });
    },
};

export default allApi;